package com.fancy.handle;

import com.fancy.emums.StatusEnum;
import com.fancy.exception.SellAuthorizeException;
import com.fancy.util.ResultUtil;
import com.fancy.vo.ResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by FancyFong on 7/9/2017.
 */
@ControllerAdvice
public class ExceptionHandle {

    /**
     * 拦截接口异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO handle(Exception e){
        return ResultUtil.error(StatusEnum.ERROR,e.getMessage());
    }

    /**
     * 拦截登录异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = SellAuthorizeException.class)
    @ResponseBody
    public ModelAndView SellAuthorizeExceptionHandle(Exception e){
        return new ModelAndView("redirect:/loginController/login");
    }

}
